_flavor=postmarketos-grate
_commit="beb89d003392a1bccf719beda4a6eb8f9a4864b2"
_config="config-$_flavor.armv7"

pkgname=linux-postmarketos-grate
pkgver=5.10.0_rc1
pkgrel=1
arch="armv7"
pkgdesc="Linux kernel with experimental patches for Tegra"
url="https://postmarketos.org"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev
	     devicepkg-dev bison flex openssl-dev xz findutils"
options="!strip !check !tracedeps pmb:cross-native"
source="
	$pkgname-$pkgver-$_commit.tar.gz::https://github.com/grate-driver/linux/archive/$_commit.tar.gz
	$_config
"
license="GPL-2.0-only"

_carch="arm"

_ksrcdir="$srcdir/linux-$_commit"

prepare() {
	default_prepare
	mkdir -p "$srcdir"/build
	cp -v "$srcdir"/$_config "$srcdir"/build/.config
	make -C "$_ksrcdir" O="$srcdir"/build ARCH="$_carch" \
		olddefconfig
}

build() {
	cd "$srcdir"/build
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine"
}

package() {
	install -Dm644 "$srcdir/build/arch/$_carch/boot/"*zImage \
		"$pkgdir/boot/vmlinuz-$_flavor"

	install -D "$srcdir/build/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"

	cd "$srcdir"/build

	local _install
	case "$CARCH" in
	aarch64*|arm*)	_install="modules_install dtbs_install" ;;
	*)		_install="modules_install" ;;
	esac

	make -j1 $_install \
		ARCH="$_carch" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_DTBS_PATH="$pkgdir/usr/share/dtb"
}
sha512sums="ce80aaffc5cbab755ba50804bdf43c4b8c814bedcb4729e2ccfc2cfa3252a0110e397794850337d38047423d9f466bf170e6d0bfa0bc9d93c0ee5556b38e1785  linux-postmarketos-grate-5.10.0_rc1-beb89d003392a1bccf719beda4a6eb8f9a4864b2.tar.gz
2a30b072391c21e8adf9e832cff5589d80fa27c0aa387fc568385c1ad3798e5741b20ee85e4b8b588dd5183e4efee15d35bff971a2e55b2ef85106a8f38be074  config-postmarketos-grate.armv7"
